
#include "TokenData.h"


namespace mjc 
{
	//define
	TokenData::mapTypeString TokenData::tokenName;
	TokenData::mapStringType TokenData::keywords;

	//Initializes and fills tokenName and keyword hash_maps with data
	void TokenData::Initialize()
	{
		tokenName[TokenType::T_NONE] = L"none";
        tokenName[TokenType::T_IDENT] = L"ident";
        tokenName[TokenType::T_NUMBER] = L"number";
        tokenName[TokenType::T_CHAR] = L"char";
        tokenName[TokenType::T_PLUS] = L"+";
        tokenName[TokenType::T_MINUS] = L"-";
        tokenName[TokenType::T_TIMES] = L"*";
        tokenName[TokenType::T_SLASH] = L"/";
        tokenName[TokenType::T_REM] = L"%";
        tokenName[TokenType::T_EQL] = L"==";
        tokenName[TokenType::T_NEQ] = L"!=";
        tokenName[TokenType::T_LSS] = L"<";
        tokenName[TokenType::T_LEQ] = L"<=";
        tokenName[TokenType::T_GTR] = L">";
        tokenName[TokenType::T_GEQ] = L">=";
        tokenName[TokenType::T_ASSIGN] = L"=";
        tokenName[TokenType::T_SEMICOLON] = L";";
        tokenName[TokenType::T_COMMA] = L",";
        tokenName[TokenType::T_PERIOD] = L".";
        tokenName[TokenType::T_LPAR] = L"(";
        tokenName[TokenType::T_RPAR] = L")";
        tokenName[TokenType::T_LBRACK] = L"[";
        tokenName[TokenType::T_RBRACK] = L"]";
        tokenName[TokenType::T_LBRACE] = L"{";
        tokenName[TokenType::T_RBRACE] = L"}";
        tokenName[TokenType::T_CLASS] = L"class";
        tokenName[TokenType::T_ELSE] = L"else";
        tokenName[TokenType::T_FINAL] = L"final";
        tokenName[TokenType::T_IF] = L"if";
        tokenName[TokenType::T_NEW] = L"new";
        tokenName[TokenType::T_PRINT] = L"print";
        tokenName[TokenType::T_PROGRAM] = L"program";
        tokenName[TokenType::T_READ] = L"read";
        tokenName[TokenType::T_RETURN] = L"return";
        tokenName[TokenType::T_VOID] = L"void";
        tokenName[TokenType::T_WHILE] = L"while";
        tokenName[TokenType::T_EOF] = L"eof";

		keywords[L"class"] = TokenType::T_CLASS;
        keywords[L"else"] = TokenType::T_ELSE;
        keywords[L"final"] = TokenType::T_FINAL;
        keywords[L"if"] = TokenType::T_IF;
        keywords[L"new"] = TokenType::T_NEW;
        keywords[L"print"] = TokenType::T_PRINT;
        keywords[L"program"] = TokenType::T_PROGRAM;
        keywords[L"read"] = TokenType::T_READ;
        keywords[L"return"] = TokenType::T_RETURN;
        keywords[L"void"] = TokenType::T_VOID;
        keywords[L"while"] = TokenType::T_WHILE;
	}

	bool TokenData::GetTokenName(const mjc::TokenType::Type &type, std::wstring &name)
	{
		mapTypeString::iterator it = tokenName.find(type);

		if(it != tokenName.end())
		{
			name = it->second;
			return true;
		}

		return false;
	}
	
	bool TokenData::GetKeywordToken(const std::wstring &keyword, mjc::TokenType::Type &type)
	{
		mapStringType::iterator it = keywords.find(keyword);

		if(it != keywords.end())
		{
			type = it->second;
			return true;
		}

		return false;
	}
}